using DotNetCore.CAP.Messages;
using DotNetCore.CAP.MQTT;
//using Microsoft.Extensions.Hosting;
//using Microsoft.EntityFrameworkCore;

namespace Sample.MQTT.Mysql
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
            //            var builder = WebApplication.CreateBuilder(args); // Fix: Ensure the required namespaces are included

            //            var cb = new ConfigurationBuilder()
            //                .SetBasePath(Directory.GetCurrentDirectory())
            //                .AddJsonFile("appsettings.json");
            //            IConfiguration configuration = cb.Build();
            //            //builder.Services.AddDbContext<AppDbContext>(option => option.UseMySQL(configuration["MySql:ConnectionString"])); //Options, If you are using EF as the ORM
            //                                                                                                                             // Add services to the container.
            //            builder.Services.AddCap(x =>
            //            {
            //                x.UseInMemoryStorage();
            //                //x.UseEntityFramework<AppDbContext>();
            //                if (configuration["MQTT:Host"] != null)
            //                {
            //                    x.UseMQTT(options =>
            //                    {
            //                        options.Server = configuration["MQTT:Host"]!;
            //                        options.Port = Convert.ToInt32(configuration["MQTT:Port"]);
            //                        options.UserName = configuration["MQTT:UserName"]!;
            //                        options.Password = configuration["MQTT:Password"]!;
            //                        options.ClientId = configuration["MQTT:ClientId"]!;
            //                        options.UseString = Convert.ToBoolean(configuration["MQTT:UseString"]);
            //                    });
            //                }
            //#if NET8_0_OR_GREATER
            //                x.UseDashboard();
            //#endif
            //                x.FailedRetryCount = 5;
            //                x.FailedThresholdCallback = failed =>
            //                {
            //                    var logger = failed.ServiceProvider.GetService<ILogger<Program>>();
            //                    logger.LogError($@"A message of type {failed.MessageType} failed after executing {x.FailedRetryCount} several times, 
            //                            requiring manual troubleshooting. Message name: {failed.Message.GetName()}");
            //                };
            //            });
            //            builder.Services.AddControllers();

            //            var app = builder.Build();

            //            // Configure the HTTP request pipeline.

            //            app.UseAuthorization();

            //            app.MapControllers();

            //            app.Run();
        }
        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.ConfigureLogging(logging =>
                    {
                        logging.ClearProviders();
                        logging.AddConsole();
                        logging.AddDebug();
                    });
                    webBuilder.UseStartup<Startup>();
                });
    }
}